﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Caching;

namespace OLAPFramework.Cache
{
    public interface ICache
    {
        /// <summary>
        /// Add an object to the cache
        /// </summary>
        /// <param name="key">Key of object</param>
        /// <param name="value">Value to store in cahce</param>
        void Add(string key, object value);

        /// <summary>
        /// Set/add an object to the cache
        /// </summary>
        /// <param name="key">Key of object</param>
        /// <param name="value">Value to store in cahce</param>
        /// <param name="timeout">The time to cache which contains that object will expire. Some caching machanithsm does not support timeout</param>
        void Add(string key, object value, TimeSpan timeout);

        /// <summary>
        /// Add an object to the cache
        /// </summary>
        /// <param name="key">Key of object</param>
        /// <param name="value">Value to store in cahce</param>
        /// <param name="dependency"></param>
        void Add(string key, object value, CacheDependency dependency);

        /// <summary>
        /// Set/add an object to the cache
        /// </summary>
        /// <param name="key">Key of object</param>
        /// <param name="value">Value to store in cahce</param>
        void Set(string key, object value);

        /// <summary>
        /// Set/add an object to the cache
        /// </summary>
        /// <param name="key">Key of object</param>
        /// <param name="value">Value to store in cahce</param>
        /// <param name="timeout">The time to cache which contains that object will expire. Some caching machanithsm does not support timeout</param>
        void Set(string key, object value, TimeSpan timeout);

        /// <summary>
        /// Check whether an object is storing in cache
        /// </summary>
        /// <param name="key">Key of object in cache</param>
        /// <returns></returns>
        bool Contains(string key);

        /// <summary>
        /// Remove all the objects stored cache
        /// </summary>
        void Flush();

        /// <summary>
        /// Get an object from cache
        /// </summary>
        /// <param name="key">Key of object in cache</param>
        /// <returns></returns>
        object Get(string key);

        /// <summary>
        /// Remove an object from cache
        /// </summary>
        /// <param name="key">Key of object need to remove</param>
        void Remove(string key);

        /// <summary>
        /// Remove an object from cache with the matching condition object's key.
        /// This will interate through out all keys in cache and decide whether 
        /// current object with current matching key need to remove from cache.
        /// </summary>
        /// <param name="matchKeyEvaluator">Evaluator is to evaluate the matching key of objects which stored in cache</param>
        void RemoveWith(Func<string, bool> matchKeyEvaluator);
    }
}
